Null perm and use with real and string variables

Although the DOORS documentation says that there is a null constant, I think it is conceptual only. I don't think there is a null constant.

(from DOORS help file):

The null constant

The constant null is used as a polymorphic value to indicate a null value. You can use it for any derived type (see Derived types). You can use it for both assignment to variables and conditional tests on variables.

Example

Object obj = null 
if (null obj) {
    ack "This object is empty"
}

 

 

NULL PERMS:

There are four perm functions used for assignment:

 

 

 

  • IconID null ()
  • real null ()
  • string null ()
  • _m null ()


There are three perm functions used for evaluation:

 

 

  • bool null (string)
  • bool null (_n)
  • bool null (real)


DOORS is one of those strange languages that can choose an overloaded function based on context. Most languages (like Java, C, C++) can pick an overloaded function based on the parameter list but NOT the function return value. DXL can but sometimes fails. You can help it along but casting to give an extra hint of which overloaded function to use.

 

 

 

IMMEDIATE VARIABLES VS. REFERENCE VARIABLES

Types like int, bool, and char are have their content right in the variable.

Allocated types like Buffer, Skip, etc. have the address of an object descriptor stored in the variable. This is made pretty clear in the documentation.

Most of the issues involving null are because string and real have no allocation function (like new() or create()) but the content is not stored in an immediate fashion. Syntax-wise they appear to be immediate values but they are not.

When you have an assigned string variable, the content is really the address of a string descriptor somewhere else in memory. Type real is similar to string. When you have an assigned real variable, the variable contains an address of a 64-bit area in memory that contains the actual real content.

Unlike the allocated types, string and real have no destructors (e.g., delete, destroy). I don't know if this content hangs out until you exit DXL or there is some garbage collection that occurs if all references to the memory go out of scope (like Java).

There seems to be a special area in memory that has a common null string descriptor and another area with null real content.

If you set string or real variable to null and print it you will get an empty string or a real value of 0.0 respectively.

As soon as you assign string or real variable, a transparent "create object" takes place and the string or real variable will contain the address of the descriptor.

This code and corresponding output will illustrate the above:

(I used some library functions I did not un-factor for publication, but I think you'll get the general idea from reading the output that follows)

 

 

 

 

ILLUSTRATION

 

 

 

real functionReturningRealVersionA() {
    // explicitly specify which null function to use
    return (real null())
}
 
real functionReturningRealVersionB() {
    // explicitly specify which null function to use
    // you can leave off the () and it still works
    return (real null)
}
 
real functionReturningRealVersionC() {
    // Even though the function clearly returns real
    // DOORS chooses the wrong null() function to execute
    return (null());
}
 
real functionReturningRealVersionD() {
    // Even though the function clearly returns real
    // DOORS chooses the wrong null() function to execute
    // There is no null constant.  It is always a function call.
    return null;
}
 
 
// DOORS (usually) knows which null function to call based on LHS (left hand side of =)
int i1 = 0x04030201;
real r1 = null();
real r2 = 0;
real r3 = null();
string str1 = null();
string str2 = "";
string str3 = null();
int i2 = 0x08070605;
 
debugLog("int content of 11 = " (int addr_ i1) "");
debugLog("(as int) i1 = " (i1) "");
 
debugLog("int content of r1 = " (int addr_ r1) "");
debugLog("(as real) r1 = " (r1) "");
 
debugLog("int content of r2 = " (int addr_ r2) "");
debugLog("(as real) r2 = " (r2) "");
 
debugLog("int content of r3 = " (int addr_ r3) "");
debugLog("(as real) r3 = " (r3) "");
 
debugLog("int content of str1 = " (int addr_ str1) "");
debugLog("(as string) str1 = '" (str1) "'");
 
debugLog("int content of str2 = " (int addr_ str2) "");
debugLog("(as string) str2 = '" (str2) "'");
 
debugLog("int content of str3 = " (int addr_ str3) "");
debugLog("(as string) str3 = '" (str3) "'");
 
debugLog("Use (string null()) directly = '" (string null()) "'");
 
debugLog("int content of 12 = " (int addr_ i2) "");
debugLog("(as int) i2 = " (i2) "");
 
 
int anAddr = PtrOps_addressOfVar(i1);
 
exploreAddresses(anAddr, 8);
 
debugLog("What does the content of r1 reference?");
exploreAddresses((int addr_ r1) , 2);
 
debugLog("What does the content of r2 reference?");
exploreAddresses((int addr_ r2) , 2);
 
debugLog("What does the content of r3 reference?");
exploreAddresses((int addr_ r3) , 2);
 
debugLog("We see r1 and r3 reference a standard \"null\" real 64 bit area that has real value of 0.0");
debugLog("We see r2 references a newly allocated (with different address) real 64 bit area that has real value of 0.0");
debugLog("Lets give r2 a non-zero value");
r2 = 1.7e308;
exploreAddresses((int addr_ r2) , 2);
debugLog("r2 = " (r2) "");
 
r2 = functionReturningRealVersionA();
debugLog("[A] r2 = " (r2) "");
 
r2 = functionReturningRealVersionB();
debugLog("[B] r2 = " (r2) "");
 
//r2 = functionReturningRealVersionC(); // causes DOORS core dump
//debugLog("[C] r2 = " (r2) "");



OUTPUT:
DEBUG.int content of 11 = 67305985
DEBUG.(as int) i1 = 67305985
DEBUG.int content of r1 = 28679024
DEBUG.(as real) r1 = 0.000000
DEBUG.int content of r2 = 151871000
DEBUG.(as real) r2 = 0.000000
DEBUG.int content of r3 = 28679024
DEBUG.(as real) r3 = 0.000000
DEBUG.int content of str1 = 22499312
DEBUG.(as string) str1 = ''
DEBUG.int content of str2 = 152383104
DEBUG.(as string) str2 = ''
DEBUG.int content of str3 = 22499312
DEBUG.(as string) str3 = ''
DEBUG.Use (string null()) directly = ''
DEBUG.int content of 12 = 134678021
DEBUG.(as int) i2 = 134678021
DEBUG.Exploring block starting at: 0x924BAEC ending at 0x924BAF4
DEBUG. DWORD # ADDRESS HEXCONTENT (DEC CONT)char (if printable)
DEBUG.0000000001 0x924BAEC = 0x04030201 (67305985)©©©©
DEBUG.0000000002 0x924BAF0 = 0x01B59B70 (28679024)©µ›p
DEBUG.0000000003 0x924BAF4 = 0x090D5E18 (151871000) ©^©
DEBUG.0000000004 0x924BAF8 = 0x01B59B70 (28679024)©µ›p
DEBUG.0000000005 0x924BAFC = 0x01574FF0 (22499312)©WOð
DEBUG.0000000006 0x924BB00 = 0x09152E80 (152383104) ©.©
DEBUG.0000000007 0x924BB04 = 0x01574FF0 (22499312)©WOð
DEBUG.0000000008 0x924BB08 = 0x08070605 (134678021)©©©©
DEBUG.What does the content of r1 reference?
DEBUG.Exploring block starting at: 0x1B59B70 ending at 0x1B59B72
DEBUG. DWORD # ADDRESS HEXCONTENT (DEC CONT)char (if printable)
DEBUG.0000000001 0x1B59B70 = 0x00000000 (0)©©©©
DEBUG.0000000002 0x1B59B74 = 0x00000000 (0)©©©©
DEBUG.What does the content of r2 reference?
DEBUG.Exploring block starting at: 0x90D5E18 ending at 0x90D5E1A
DEBUG. DWORD # ADDRESS HEXCONTENT (DEC CONT)char (if printable)
DEBUG.0000000001 0x90D5E18 = 0x00000000 (0)©©©©
DEBUG.0000000002 0x90D5E1C = 0x00000000 (0)©©©©
DEBUG.What does the content of r3 reference?
DEBUG.Exploring block starting at: 0x1B59B70 ending at 0x1B59B72
DEBUG. DWORD # ADDRESS HEXCONTENT (DEC CONT)char (if printable)
DEBUG.0000000001 0x1B59B70 = 0x00000000 (0)©©©©
DEBUG.0000000002 0x1B59B74 = 0x00000000 (0)©©©©
DEBUG.We see r1 and r3 reference a standard "null" real 64 bit area that has real value of 0.0
DEBUG.We see r2 references a newly allocated (with different address) real 64 bit area that has real value of 0.0
DEBUG.Lets give r2 a non-zero value
DEBUG.Exploring block starting at: 0x90D5E20 ending at 0x90D5E22
DEBUG. DWORD # ADDRESS HEXCONTENT (DEC CONT)char (if printable)
DEBUG.0000000001 0x90D5E20 = 0x30773B76 (813120374)0w;v
DEBUG.0000000002 0x90D5E24 = 0x7FEE42D1 (2146321105)©îBÑ
DEBUG.r2 = 169999999999999990000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000
DEBUG.[A] r2 = 0.000000
DEBUG.[B] r2 = 0.000000



 

 

 

  • Credits to Mathias Mamsch for explaining something similar to me about a year ago.

 

 


SystemAdmin - Wed Oct 26 15:51:18 EDT 2011

Re: Null perm and use with real and string variables
llandale - Thu Oct 27 14:26:52 EDT 2011

This is interesting. It would be lot more interesting if you would translate into practical advise.
Such as routinely caste in a return statement: return(Buffer null)
Such as routinely caste when used in comparison statements: if (a(1) == string null)

  • Louie

Re: Null perm and use with real and string variables
SystemAdmin - Fri Oct 28 11:58:01 EDT 2011

llandale - Thu Oct 27 14:26:52 EDT 2011
This is interesting. It would be lot more interesting if you would translate into practical advise.
Such as routinely caste in a return statement: return(Buffer null)
Such as routinely caste when used in comparison statements: if (a(1) == string null)

  • Louie

I'd say the practical advice is:

  • Realize that all the DXL null identifiers are really functions (not constants)
  • DXL tries to pick the right one based on context.
  • If something is done that is valid but crashes DOORS, try giving the DXL parser a little hint by casting the null variation you desire.
  • If have a simple expression like the below DXL picks the right null.
real r1 = null();     // () optional
string str1 = null(); // () optional

 


I have not found all the situations but if I look at code and think to myself "this is correct, why is DOORS crashing?"

 

 

  • Try an explicit cast to give the DXL parser a little hint. Often this remedies the problem.
  • Example - Clearly this function is declared to return a real but apparently the DXL parser misses this fact and chooses the wring null() function.

 

 

// DOORS will crash if you do this (BUG if you ask me)
real thisShouldReturnARealVariationOfNull() {
    return null;
}
real r1 = thisShouldReturnARealVariationOfNull();



As a kluge, you can toss in a an explicit cast and you will have instant karma



 

 

 

// DOORS will use the right null() function if you cast
real thisShouldReturnARealVariationOfNull() {
    return (real null);
}
real r1 = thisShouldReturnARealVariationOfNull();



Another probably minor point is it is more efficient to set string variables to null() than "".
Here is the difference:



 

 

 

  • This creates a new string descriptor in memory that set to an zero length string

 

string str1 = ""; // str1 contains address of new string descriptor

 

 

  • This has str1, str2, str3 reference a static area of memory that contains a stock empty string. No extra create string occurs. You can see the address contained in str1, str2, and str3 is all the same.

 

 

 

string str1 = null(); // Here null() returns the address of a stock empty string
string str2 = null(); // Here null() returns the address of a stock empty string
string str3 = null(); // Here null() returns the address of a stock empty string



If you pass null as a parameter, (although you shouldn't need to) it is wise the put in a cast to be certain the address of the right null() function is pushed.



 

Re: Null perm and use with real and string variables
SystemAdmin - Fri Oct 28 12:08:11 EDT 2011

SystemAdmin - Fri Oct 28 11:58:01 EDT 2011

I'd say the practical advice is:

  • Realize that all the DXL null identifiers are really functions (not constants)
  • DXL tries to pick the right one based on context.
  • If something is done that is valid but crashes DOORS, try giving the DXL parser a little hint by casting the null variation you desire.
  • If have a simple expression like the below DXL picks the right null.
real r1 = null();     // () optional
string str1 = null(); // () optional

 


I have not found all the situations but if I look at code and think to myself "this is correct, why is DOORS crashing?"

 

 

  • Try an explicit cast to give the DXL parser a little hint. Often this remedies the problem.
  • Example - Clearly this function is declared to return a real but apparently the DXL parser misses this fact and chooses the wring null() function.

 

 

// DOORS will crash if you do this (BUG if you ask me)
real thisShouldReturnARealVariationOfNull() {
    return null;
}
real r1 = thisShouldReturnARealVariationOfNull();



As a kluge, you can toss in a an explicit cast and you will have instant karma



 

 

 

// DOORS will use the right null() function if you cast
real thisShouldReturnARealVariationOfNull() {
    return (real null);
}
real r1 = thisShouldReturnARealVariationOfNull();



Another probably minor point is it is more efficient to set string variables to null() than "".
Here is the difference:



 

 

 

  • This creates a new string descriptor in memory that set to an zero length string

 

string str1 = ""; // str1 contains address of new string descriptor

 

 

  • This has str1, str2, str3 reference a static area of memory that contains a stock empty string. No extra create string occurs. You can see the address contained in str1, str2, and str3 is all the same.

 

 

 

string str1 = null(); // Here null() returns the address of a stock empty string
string str2 = null(); // Here null() returns the address of a stock empty string
string str3 = null(); // Here null() returns the address of a stock empty string



If you pass null as a parameter, (although you shouldn't need to) it is wise the put in a cast to be certain the address of the right null() function is pushed.



 

CORRECTION:
  • The last sentence should read:

If you pass null as a parameter, (although you shouldn't need to) it is wise the put in a cast to be certain the right null() function will be called.

The return value of the null() function is what gets is pushed to the parameter list.